package com.sbxBase.controller;

import com.sbxBase.service.FriendsApplyService;
import com.common.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "好友申请")
@RestController
@RequestMapping("/friendsApply")
public class FriendsApplyController {

    @Resource
    private FriendsApplyService friendsService;

    @PostMapping("/{action}/apply/{id}")
    @ApiOperation("处理好友申请")
    public Result apply(@ApiParam("agree 确认,refuse 拒绝") @PathVariable String action,
                        @ApiParam("申请id") @PathVariable String id,
                        @ApiParam("处理结果") @RequestBody String result) {
        friendsService.apply(action, id,result);
        return Result.success();
    }

    @GetMapping("/apply")
    @ApiOperation("获取申请列表分页")
    public Result getApplyPage(@ApiParam(value = "起始页", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageIndex,
                               @ApiParam(value = "每页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize) {

        return Result.page(friendsService.getApplyPage(pageIndex, pageSize));
    }

    @PostMapping("{userId}/submitApply")
    @ApiOperation("申请添加好友")
    public Result submitApply(@PathVariable String userId,
                              @RequestBody String cause) {
        friendsService.submitApply(userId, cause);
        return Result.success();
    }
}
